home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Newton Sample Code 1.2 / Utility Functions / NewTextFuncs-1 / NewTextFuncs.text < prev    next >
Encoding:
Text File  |  1994-07-07  |  9.3 KB  |  386 lines  |  [TEXT/MPS ]

  1. // Copyright, ©1994 Apple Computer. All rights reserved.
  2.  
  3. // app constants
  4.  
  5. constant kAppSymbol := '|NewTextFuncs:PIEDTS|;
  6. constant kAppname := "New Text Funcs" ;
  7.  
  8. constant kAppMaxWidth := 240 ;
  9. constant kAppMaxHeight := 336 ;
  10.  
  11.  
  12. // error strings
  13. DefConst('kAppErrors,
  14.     ["There is no Source Text to display",
  15.     ]);
  16.     
  17. constant kNoTextError := 0 ;
  18. // ---- End Project Data ----
  19.  
  20.  
  21. // ---- File NewTextFuncs.t ----
  22. myBase :=
  23.    {viewBounds: {left: 0, top: 2, right: 236, bottom: 310},
  24.     viewFormat: 83951953,
  25.     viewSetupFormScript:
  26.       func()
  27.       begin
  28.           a := GetAppParams();
  29.           viewBounds := RelBounds(a.AppAreaLeft, a.AppAreaTop,
  30.               MIN(a.AppAreaWidth, kAppMaxWidth),
  31.               MIN(a.AppAreaHeight, kAppMaxHeight));
  32.       end,
  33.     DoError:
  34.       func(errorID, params)
  35.       begin
  36.           local errorString := Clone(kAppErrors[errorID]) ;
  37.           if params then
  38.               errorString := ParamStr(errorString, params) ;
  39.           :Notify(kNotifyAlert, EnsureInternal(kAppName), errorString);
  40.       end,
  41.     declareSelf: 'base,
  42.     DrawFunkyText:
  43.       func(myText, funkyFontFrame)
  44.       begin
  45.               local b := :LocalBox();
  46.               local bounds := SetBounds(0, 0, 0, 0) ; // temporary use only
  47.       
  48.               // get the bounding box required for the text
  49.               TextBounds(myText, funkyFontFrame, bounds);
  50.       
  51.                           // just to make things look nice, clear our view
  52.               :DrawShape(MakeRect(b.left, b.top, b.right, b.bottom), {fillpattern:vfWhite});
  53.       
  54.               // now have some fun blasting the text around
  55.               local height := bounds.bottom - bounds.top;
  56.               local width := bounds.right - bounds.left;
  57.       
  58.               // make the text fit completely horizontally within us
  59.               local horizontalMax := (b.right - b.left) - width;
  60.       
  61.               // make the text fit completely vertically within us
  62.               local verticalMax := (b.bottom - b.top) - height;
  63.               
  64.               for i := 1 to 100 do
  65.                   TextBox(myText, funkyFontFrame,
  66.                       RelBounds(Random(0, horizontalMax), Random(0, verticalMax), width, height));    
  67.       
  68.               :Dirty();          // redraw our entire application
  69.               RefreshViews();    // refresh immediately so the textbutton 'unhilite' will look pretty
  70.       end,
  71.     _proto: protoApp,
  72.     debug: "myBase"
  73.    };
  74.  
  75. theText := /* child of myBase */
  76.    {viewFlags: 33553921,
  77.     viewFormat: 209233,
  78.     viewlinespacing: 20,
  79.     viewBounds: {left: 6, top: 25, right: 234, bottom: 95},
  80.     text: "Some text with\nline breaks in places\nthat are breaks",
  81.     viewFont: nil,
  82.     viewSetupFormScript:
  83.       func()
  84.       begin
  85.           viewFont := userconfiguration.userFont ;
  86.       end,
  87.     viewclass: 81,
  88.     debug: "theText"
  89.    };
  90. // View theText is declared to myBase
  91.  
  92.  
  93.  
  94. _view000 := /* child of myBase */
  95.    {text: "Display Text",
  96.     buttonClickScript:
  97.       func()
  98.       begin
  99.           local bounds := SetBounds(0, 0, 0, 0) ;
  100.           local funkyFontFrame := {font: FontStyle:GetFontFrame(),
  101.               justification: Justification:GetJustification()};
  102.               
  103.           if StrLen(theText.text) < 1 then
  104.               return :DoError(kNoTextError, nil) ;
  105.               
  106.       
  107.           local myText := theText.text ;
  108.       
  109.           // do not need to display the new viewbounds
  110.           newViewBounds:Close();
  111.           targetText:Close();
  112.               
  113.           if functionType.clusterValue = 'TextBox then
  114.           begin
  115.               base:DoDrawing('DrawFunkyText, [myText, funkyFontFrame]);
  116.           end;
  117.           else begin // if we are using the function called TextBounds
  118.               local newBounds := Clone(bounds);
  119.       
  120.               TextBounds(myText, funkyFontFrame, newBounds);
  121.       
  122.               newViewBounds:SetText(bounds, newBounds);
  123.       
  124.               targetText.text := myText ;
  125.               targetText.funkyFont := funkyFontFrame ;
  126.               targetText.textBounds := newBounds ;
  127.               
  128.               targetText:Open();
  129.               newViewbounds:Open();
  130.           end;
  131.       end,
  132.     viewBounds: {left: 10, top: 194, right: 130, bottom: 210},
  133.     _proto: protoTextButton
  134.    };
  135.  
  136.  
  137.  
  138. targetText := /* child of myBase */
  139.    {viewBounds: {left: 9, top: 117, right: 231, bottom: 187},
  140.     viewFormat: 336,
  141.     viewEffect: 8625185,
  142.     viewFlags: 0,
  143.     text: "",
  144.     viewDrawScript:
  145.       func()
  146.       begin
  147.           TextBox(text, funkyFont, textBounds);
  148.       end,
  149.     funkyFont: nil,
  150.     TextBounds: nil,
  151.     viewclass: 74,
  152.     debug: "targetText"
  153.    };
  154. // View targetText is declared to myBase
  155.  
  156.  
  157.  
  158. functionType := /* child of myBase */
  159.    {viewBounds: {left: 141, top: 261, right: 227, bottom: 299},
  160.     clusterValue: 'TextBox,
  161.     viewFormat: 336,
  162.     _proto: protoRadioCluster,
  163.     debug: "functionType"
  164.    };
  165. // View functionType is declared to myBase
  166.  
  167. _view001 := /* child of functionType */
  168.    {buttonValue: 'TextBox,
  169.     viewBounds: {left: 9, top: 5, right: 75, bottom: 21},
  170.     text: "TextBox",
  171.     _proto: protoRadioButton
  172.    };
  173.  
  174.  
  175.  
  176. _view002 := /* child of functionType */
  177.    {buttonValue: 'TextBounds,
  178.     viewBounds: {left: 9, top: 21, right: 75, bottom: 37},
  179.     text: "TextBounds",
  180.     _proto: protoRadioButton
  181.    };
  182.  
  183.  
  184.  
  185.  
  186.  
  187. _view003 := /* child of myBase */
  188.    {text: "Use Function:",
  189.     viewBounds: {left: 145, top: 254, right: 207, bottom: 270},
  190.     viewFormat: 1,
  191.     viewFont: simpleFont9,
  192.     _proto: protoStaticText
  193.    };
  194.  
  195.  
  196.  
  197. _view004 := /* child of myBase */
  198.    {text: "Source Text",
  199.     viewBounds: {left: 8, top: 8, right: 72, bottom: 24},
  200.     _proto: protoStaticText
  201.    };
  202.  
  203.  
  204.  
  205. _view005 := /* child of myBase */
  206.    {text: "Target View",
  207.     viewBounds: {left: 8, top: 100, right: 72, bottom: 116},
  208.     _proto: protoStaticText
  209.    };
  210.  
  211.  
  212.  
  213. FontStyle := /* child of myBase */
  214.    {viewFlags: 1,
  215.     viewFormat: 336,
  216.     viewBounds: {left: 9, top: 241, right: 119, bottom: 303},
  217.     GetFontFrame:
  218.       func()
  219.       begin
  220.           {family: FontFamily:GetFamily(),
  221.            face: FontFace:GetFace(),
  222.            size: FontSize:GetSize()}
  223.       end,
  224.     viewclass: 74,
  225.     debug: "FontStyle"
  226.    };
  227. // View FontStyle is declared to myBase
  228.  
  229. FontFamily := /* child of FontStyle */
  230.    {viewBounds: {left: 5, top: 7, right: 107, bottom: 21},
  231.     viewSetupFormScript:
  232.       func()
  233.       begin
  234.           self.labelCommands := 
  235.               foreach slot, val deeply in fonts collect
  236.                       Capitalize(SprintObject(slot));
  237.           inherited:?viewSetupFormScript()
  238.       end,
  239.     text: "Family",
  240.     GetFamily:
  241.       func()
  242.       begin
  243.           Intern(entryLine.text);
  244.       end,
  245.     _proto: protoLabelPicker,
  246.     debug: "FontFamily"
  247.    };
  248. // View FontFamily is declared to FontStyle
  249.  
  250.  
  251.  
  252. FontFace := /* child of FontStyle */
  253.    {viewBounds: {left: 5, top: 27, right: 107, bottom: 41},
  254.     text: "Face",
  255.     labelCommands: ["Normal", "Bold", "Italic", "Underline"],
  256.     labelActionScript:
  257.       func(cmd)
  258.       begin
  259.           currIndex := cmd;
  260.       end,
  261.     currIndex: 0,
  262.     GetFace:
  263.       func()
  264.       begin
  265.           if currIndex = 0 then
  266.               kFaceNormal;
  267.           else if currIndex = 1 then
  268.               kFaceBold;
  269.           else if currIndex = 2 then
  270.               kFaceItalic;
  271.           else
  272.               kFaceUnderline;
  273.       end,
  274.     _proto: protoLabelPicker,
  275.     debug: "FontFace"
  276.    };
  277. // View FontFace is declared to FontStyle
  278.  
  279.  
  280.  
  281. FontSize := /* child of FontStyle */
  282.    {viewBounds: {left: 5, top: 47, right: 107, bottom: 61},
  283.     text: "Size",
  284.     labelCommands: ["9", "10", "12", "14", "18"],
  285.     currIndex: 0,
  286.     labelActionScript:
  287.       func(cmd)
  288.       begin
  289.           currIndex := cmd;
  290.       end,
  291.     GetSize:
  292.       func()
  293.       begin
  294.           if currIndex = 0 then
  295.               9;
  296.           else if currIndex = 1 then
  297.               10;
  298.           else if currIndex = 2 then
  299.               12;
  300.           else if currIndex = 3 then
  301.               14;
  302.           else
  303.               18;
  304.       end,
  305.     _proto: protoLabelPicker,
  306.     debug: "FontSize"
  307.    };
  308. // View FontSize is declared to FontStyle
  309.  
  310.  
  311.  
  312.  
  313.  
  314. _view006 := /* child of myBase */
  315.    {text: "Use Font:",
  316.     viewBounds: {left: 12, top: 234, right: 56, bottom: 250},
  317.     viewFont: simpleFont9,
  318.     viewFormat: 1,
  319.     _proto: protoStaticText
  320.    };
  321.  
  322.  
  323.  
  324. Justification := /* child of myBase */
  325.    {viewBounds: {left: 9, top: 217, right: 131, bottom: 235},
  326.     labelCommands: ["Left", "Center", "Right"],
  327.     GetJustification:
  328.       func()
  329.       begin
  330.           Intern(entryLine.text);
  331.       end,
  332.     text: "Justification",
  333.     _proto: protoLabelPicker,
  334.     debug: "Justification"
  335.    };
  336. // View Justification is declared to myBase
  337.  
  338.  
  339.  
  340. newViewbounds := /* child of myBase */
  341.    {viewFlags: 0,
  342.     viewFormat: 336,
  343.     viewBounds: {left: 137, top: 193, right: 231, bottom: 251},
  344.     viewFont: {family: 'espy, face: kFaceNormal, size: 9},
  345.     viewDrawScript:
  346.       func()
  347.       begin
  348.           TextBox(displayText, {font: viewFont, justification: 'center},
  349.               :LocalBox());
  350.       end,
  351.     viewEffect: 8625185,
  352.     sourceText: "Source Viewbounds:\n^0\nNew Viewbounds:\n^1",
  353.     displaytext: nil,
  354.     SetText:
  355.       func(sourceBounds, newBounds)
  356.       begin
  357.           local s := "(", n := "(" ;
  358.           foreach x in sourceBounds do
  359.               s := s & NumberStr(x) & ", ";
  360.           StrMunger(s, StrLen(s) - 2, 2, ")", 0, 1);
  361.               
  362.           foreach x in newBounds do
  363.               n := n & NumberStr(x) & ", ";
  364.           StrMunger(n, StrLen(n) - 2, 2, ")", 0, 1);
  365.       
  366.           displayText := ParamStr(sourceText, [s, n]);
  367.       end,
  368.     viewclass: 74,
  369.     debug: "newViewbounds"
  370.    };
  371. // View newViewbounds is declared to myBase
  372.  
  373.  
  374.  
  375. // After Script for "myBase"
  376. thisView := myBase;
  377. // Copyright, ©1994 Apple Computer. All rights reserved.
  378. thisView.title := kAppName;
  379.  
  380.  
  381.  
  382.  
  383.  
  384. // ---- Beginning of section for non used Layout files ----
  385.  
  386. // End of output